package com.ruoyi.project.cms.client.controller;

import java.util.List;

import com.ruoyi.project.cms.client.domain.CmsClient;
import com.ruoyi.project.cms.client.service.ICmsClientService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;


@Controller
@RequestMapping("/cms/client")
public class CmsClientController extends BaseController
{
    private String prefix = "cms/client";

    @Autowired
    private ICmsClientService cmsClientService;

/*
    @RequiresPermissions("cms:client:view")
*/
    @GetMapping()
    public String client()
    {
        return prefix + "/client";
    }

    /**
     * 查询clientCURD列
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmsClient cmsClient)
    {
        startPage();
        List<CmsClient> list = cmsClientService.selectCmsClientList(cmsClient);
        return getDataTable(list);
    }

    /**
     * 导出clientCURD列表
     */
    @Log(title = "clientCURD", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsClient cmsClient)
    {
        List<CmsClient> list = cmsClientService.selectCmsClientList(cmsClient);
        ExcelUtil<CmsClient> util = new ExcelUtil<CmsClient>(CmsClient.class);
        return util.exportExcel(list, "client");
    }

    /**
     * 新增client
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存clientCURD
     */
    @Log(title = "clientCURD", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmsClient cmsClient)
    {
        return toAjax(cmsClientService.insertCmsClient(cmsClient));
    }

    /**
     * 修改client
     */
    @GetMapping("/edit/{cid}")
    public String edit(@PathVariable("cid") Integer cid, ModelMap mmap)
    {
        CmsClient cmsClient = cmsClientService.selectCmsClientById(cid);
        mmap.put("cmsClient", cmsClient);
        return prefix + "/edit";
    }

    /**
     * 修改保存clientCURD
     */
    @Log(title = "clientCURD", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmsClient cmsClient)
    {
        return toAjax(cmsClientService.updateCmsClient(cmsClient));
    }

    /**
     * 删除clientCURD
     */
    @Log(title = "clientCURD", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmsClientService.deleteCmsClientByIds(ids));
    }
}
